#ifndef __CHAR_DRV_H__
#define __CHAR_DRV_H__

#include <linux/ioctl.h>

typedef struct {
	unsigned int reg;
	unsigned int val;
	unsigned int flag; //1:read 2:write
} RegParams;

typedef struct {
	unsigned int reg;
	unsigned int status;
	unsigned int flag; //1:read 2:write
} StatusParams;

typedef struct {
	unsigned long vir_src;
	unsigned long phy_src;
	unsigned int bytes;
} PcmDataParams;
/* DMA Command */
typedef union
{
    uint64_t all;
    struct
    {
        uint64_t SrcAddr_47_3:45;   // 44:0 Source Address[47:3]
        uint64_t LogicOp:3;         // 47:45 Logic Operation: 0:None 1:NOT 2:XOR 3:OR 4:AND
        uint64_t rsvd:2;            // 49:48 Rsvd
        uint64_t Tag:6;             // 55:50 Command Tag
        uint64_t Opcode:8;          // 63:56 Operation Code
    };
}DMAB0CmdDw0_T;

typedef union
{
    uint64_t all;
    struct
    {
        uint64_t Xstep_SrcDescNum:16;  // 15:0 XStep(OP80/81/84) or SrcDescriptorNum(OP82/83)
        uint64_t DstAddr_47_3:45;   // 60:16 Destination Address
        uint64_t LenUnit:3;         // 63:61 Length Unit: 8B/16B/32B/64B/1KB
    };
}DMAB0CmdDw1_T;

typedef union
{
    uint64_t all;
    struct
    {
        uint64_t PcieFuncNum:1;                 // 0
        uint64_t PcieDontSnoop:1;               // 1
        uint64_t IntrEn:1;                      // 2
        uint64_t rsvd1:1;                       // 3
        uint64_t DstrideLow_PatternLen:8;       // 11:4 DstStride[7:0](OP84) or PatternLocation
        uint64_t DstrideHigh_PatternLoc:8;      // 19:12 DstStride[15:8](OP84) or PatternLocation
        uint64_t Sstride_DWriteLenLow:16;       // 35:20 SrcStride(OP84) or DirectWriteLen[15:0]
        uint64_t Ystep_DstDescNum_DstXferLen_DWriteLenHigh:16;  // 51:36 Ystep(OP84) or DstDescNum(OP81/83)
                                                                //       or DstXferLen(OP82) or DirectWriteLen[24:16]
        uint64_t DstAddrMode:4;     // 55:52 Destination Address Mode
        uint64_t SrcAddrMode:4;     // 59:56 Source Address Mode
        uint64_t rsvd2:4;           // 63:60 Rsvd
    };
}DMAB0CmdDw2_T;

typedef union
{
    uint32_t cmd32[6];
    uint64_t cmd64[3];
    struct
    {
        DMAB0CmdDw0_T dw0;
        DMAB0CmdDw1_T dw1;
        DMAB0CmdDw2_T dw2;
    };
}VDMA_B0_CmdData_T;

typedef struct {
	uint32_t pid;
	uint32_t size;
} CONFIG_T;

typedef struct {
	uint32_t size;
	uint8_t *data;
} DATA_T;

#define TLS_AUDIO_IOCTL_MAGIC 'k'

#define TLS_AUDIO_IOCTL_INIT_ASYNC_READ   	_IOR(TLS_AUDIO_IOCTL_MAGIC, 1, CONFIG_T *)
#define TLS_AUDIO_IOCTL_READ			 	_IOWR(TLS_AUDIO_IOCTL_MAGIC, 2, uint8_t *)
#define TLS_AUDIO_IOCTL_STOP_READ	    	_IOR(TLS_AUDIO_IOCTL_MAGIC, 3, unsigned long *)
#define TLS_AUDIO_IOCTL_WRITE			    _IOR(TLS_AUDIO_IOCTL_MAGIC, 4, DATA_T *)
#define TLS_AUDIO_IOCTL_STOP_WRITE			_IOR(TLS_AUDIO_IOCTL_MAGIC, 5, unsigned long *)


#define TLS_AUDIO_IOCTL_DEINIT_REG	 		_IOWR(TLS_AUDIO_IOCTL_MAGIC, 6, RegParams*)
#define TLS_AUDIO_IOCTL_VDMA_H2D	 		_IOWR(TLS_AUDIO_IOCTL_MAGIC, 7, unsigned char *)
#define TLS_AUDIO_IOCTL_SET_PTR		 		_IOWR(TLS_AUDIO_IOCTL_MAGIC, 8, PcmDataParams *)
#define TLS_AUDIO_IOCTL_GET_BUFFER         	_IOWR(TLS_AUDIO_IOCTL_MAGIC, 9, PcmDataParams *)
#define TLS_AUDIO_IOCTL_FREE_BUFFER 		_IOWR(TLS_AUDIO_IOCTL_MAGIC, 10, PcmDataParams *)

#define TLS_AUDIO_IOCTL_HARDRESET 			_IO(TLS_AUDIO_IOCTL_MAGIC, 15) /* debugging tool */
#define TLS_AUDIO_IOCTL_MAXNR 15
#define TLS_AUDIO_GET_STAUS_ACPU 				(0x99)
#define TLS_AUDIO_GET_STAUS_VDMACH3 			(0x98)

#endif /* __CHAR_DRV_H__ */
